<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%
  String path = request.getContextPath();
%>
<!DOCTYPE HTML>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <meta http-equiv="pragma" content="no-cache"/>
  <meta http-equiv="cache-control" content="no-cache"/>
  <meta http-equiv="expires" content="0"/>
  <title>用户列表</title>
  <link rel="stylesheet" href="<%=path %>/skin/default/css/button.css" type="text/css"/>
  <link rel="stylesheet" href="<%=path %>/scripts/zTree/css/zTreeStyle/zTreeStyle.css" type="text/css"/>

  <script type="text/javascript" src="<%=path %>/scripts/jquery/jquery-1.8.2.min.js"></script>
  <script type="text/javascript" src="<%=path %>/scripts/zTree/jquery.ztree.core-3.0.min.js"></script>
  <script type="text/javascript" src="<%=path %>/scripts/zTree/jquery.ztree.excheck-3.0.js"></script>
  <script type="text/javascript" src="<%=path %>/scripts/zTree/jquery.ztree.buttons.js"></script>
  <script type="text/javascript">
    $(function () {
      $.ajaxSetup({cache: false, async: false});
      var setting = {
        check: {
          enable: true,
          chkStyle: "radio",
          radioType: "all"
        },
        view: {
          dblClickExpand: false
        },
        data: {
          simpleData: {
            enable: true
          }
        },
        callback: {
          onClick: zTreeOnClick,
          onCheck: zTreeonCheck
        }
      };
      var dataMaker = function () {
        var nodes = [];
        $.getJSON("<%=path %>/travel/agency/List",function(data){
          if(data != null){
            var p = {id:"0",name:"旅游社",open:false,nocheck: true,icon:"<%=path %>/scripts/zTree/css/zTreeStyle/img/diy/1_close.png"};
            nodes.push(p);
            $.each(data,function(i,item){
              var h = {id:item.id,pId:"0",name:item.agencyName,code:item.agencyCode};
              nodes.push(h);
            });
          }
        });
        return nodes;
      };
      var zNodes = dataMaker();

      function zTreeOnClick(event, treeId, treeNode) {
        if (!treeNode.isParent) {
          var zTree = $.fn.zTree.getZTreeObj(treeId);
          zTree.checkNode(treeNode, !treeNode.checked, null, true);
          return false;
        }
      }

      function zTreeonCheck(event, treeId, treeNode) {
        var zTree = $.fn.zTree.getZTreeObj(treeId);
        var nodes = zTree.getCheckedNodes(true);
        $.each(nodes, function (key, item) {
          $("#node").val(item.id);
          $("#nodeText").val(item.name);
        });
      }

      $(document).ready(function () {
        $.fn.zTree.init($("#travelAgency"), setting, zNodes);
        var opts = {
          btnBind: "btnBind",
          closeBtn: "btnClose",
          node: "node",
          code:"workUnit",
          name:"workUnitName"
        };
        closeClick(opts);
        bindTravelAgencyClick(opts);
      });
    });
  </script>
</head>
<body>
<div class="content_wrap">
  <ul id="travelAgency" class="ztree"></ul>
</div>
<div class="bottomBar">
  <div class="fr" style="margin-right: 10px;">
    <input type="hidden" id="node" name="node" value=""/>
    <input type="hidden" id="nodeText" name="nodeText" value=""/>
    <input type="button" id="btnBind" name="btnBind" class="btn btn82 btn_save_bottom" value="确 定"/>
    <input type="button" id="btnClose" name="btnClose" class="btn btn82 btn_close" value="关 闭"/>
  </div>
</div>
</body>
</html>